﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using CubicFWNet.Data.SystemManager;
using CubicFWNet.Data.ViewModal;

namespace CubicFWNet.Application.SystemManager
{
    public class FinanceCostApp
    {
        private FinanceCostRepository _service = new FinanceCostRepository();

        public int Add(FinanceCost web)
        {
            return _service.Insert(web);
        }

        public int Update(FinanceCost web)
        {
            return _service.Update(web);
        }

        public IEnumerable<ProductTechnologyView> GetList(int status, int fcStatus, string productName, string number, DateTime beginTime, DateTime endTime)
        {
            return _service.GetList(status, fcStatus, productName, number, beginTime, endTime).OrderByDescending(a => a.ApplyTime);
            //return _service.IQueryable().Where(a => a.Status == status || status == -10).AsQueryable().OrderByDescending(a => a.CreateTime);
        }

        public FinanceCost GetSingleFinanceCostByOrderId(Guid orderId)
        {
            return _service.FindEntity(a => a.OrderId == orderId);
        }
        public FinanceCost GetSingleFinanceCostByOrderProductId(Guid orderProductId)
        {
            return _service.FindEntity(a => a.OrderProductId == orderProductId);
        }

        public int GetCountFinanceCostByOrderProductId(Guid orderProductId)
        {
            return _service.IQueryable(a => a.OrderProductId == orderProductId).ToList().Count();
        }

        /// <summary>
        /// 获取在相同订单下所有未审核的价格核算条数
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public int GetNoPassFinanceCostByOrderId(Guid orderId)
        {
            return _service.IQueryable().Where(a => a.OrderId == orderId && a.Status == -1).ToList().Count();
        }

    }
}
